﻿using FMStudio.Domain.SQLite;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;

namespace FMStudio.Documents.DataDocument
{
    [Export(typeof(IDocument)), Export]
    public class DataDocument : Document
    {
        #region Fields
        private FMStudioEntities entities;
        private ObservableCollection<AuditBill> auditBills;
        private ObservableCollection<AuditType> auditTypes;
        private ObservableCollection<Bill> bills;
        private ObservableCollection<City> cities;
        private ObservableCollection<Currency> currencies;
        private ObservableCollection<CurrencyExchange> currencyExchanges;
        private ObservableCollection<Item> items;
        private ObservableCollection<ItemPrice> itemPrices;
        private ObservableCollection<Market> markets;
        private ObservableCollection<PayType> payTypes;
        private ObservableCollection<PayTypeCategory> payTypeCategories;
        private ObservableCollection<Trademark> trademarks;
        private ObservableCollection<UseType> useTypes;
        private ObservableCollection<UseTypeCategory> useTypeCategories;
        #endregion


        public DataDocument()
            : base(true)
        {
        }

        ~DataDocument()
        {
            if (this.entities != null)
            {
                this.entities.Dispose();
            }
        }


        #region Properties
        public FMStudioEntities Entities
        {
            get { return this.entities; }
            set { this.entities = value; }
        }

        public ObservableCollection<AuditBill> AuditBills
        {
            get
            {
                if (this.auditBills == null && this.entities != null)
                {
                    this.auditBills = new EntityObservableCollection<AuditBill>(this.entities.AuditBills);
                }
                return this.auditBills;
            }
        }

        public ObservableCollection<AuditType> AuditTypes
        {
            get
            {
                if (this.auditTypes == null && this.entities != null)
                {
                    this.auditTypes = new EntityObservableCollection<AuditType>(this.entities.AuditTypes);
                }
                return this.auditTypes;
            }
        }

        public ObservableCollection<Bill> Bills
        {
            get
            {
                if (this.bills == null && this.entities != null)
                {
                    this.bills = new EntityObservableCollection<Bill>(this.entities.Bills);
                }
                return this.bills;
            }
        }

        public ObservableCollection<City> Cities
        {
            get
            {
                if (this.cities == null && this.entities != null)
                {
                    this.cities = new EntityObservableCollection<City>(this.entities.Cities);
                }
                return this.cities;
            }
        }

        public ObservableCollection<Currency> Currencies
        {
            get
            {
                if (this.currencies == null && this.entities != null)
                {
                    this.currencies = new EntityObservableCollection<Currency>(this.entities.Currencies);
                }
                return this.currencies;
            }
        }

        public ObservableCollection<CurrencyExchange> CurrencyExchanges
        {
            get
            {
                if (this.currencyExchanges == null && this.entities != null)
                {
                    this.currencyExchanges = new EntityObservableCollection<CurrencyExchange>(this.entities.CurrencyExchanges);
                }
                return this.currencyExchanges;
            }
        }

        public ObservableCollection<Item> Items
        {
            get
            {
                if (this.items == null && this.entities != null)
                {
                    this.items = new EntityObservableCollection<Item>(this.entities.Items);
                }
                return this.items;
            }
        }

        public ObservableCollection<ItemPrice> ItemPrices
        {
            get
            {
                if (this.itemPrices == null && this.entities != null)
                {
                    this.itemPrices = new EntityObservableCollection<ItemPrice>(this.entities.ItemPrices);
                }
                return this.itemPrices;
            }
        }

        public ObservableCollection<Market> Markets
        {
            get
            {
                if (this.markets == null && this.entities != null)
                {
                    this.markets = new EntityObservableCollection<Market>(this.entities.Markets);
                }
                return this.markets;
            }
        }

        public ObservableCollection<PayType> PayTypes
        {
            get
            {
                if (this.payTypes == null && this.entities != null)
                {
                    this.payTypes = new EntityObservableCollection<PayType>(this.entities.PayTypes);
                }
                return this.payTypes;
            }
        }

        public ObservableCollection<PayTypeCategory> PayTypeCategories
        {
            get
            {
                if (this.payTypeCategories == null && this.entities != null)
                {
                    this.payTypeCategories = new EntityObservableCollection<PayTypeCategory>(this.entities.PayTypeCategories);
                }
                return this.payTypeCategories;
            }
        }

        public ObservableCollection<Trademark> Trademarks
        {
            get
            {
                if (this.trademarks == null && this.entities != null)
                {
                    this.trademarks = new EntityObservableCollection<Trademark>(this.entities.Trademarks);
                }
                return this.trademarks;
            }
        }

        public ObservableCollection<UseType> UseTypes
        {
            get
            {
                if (this.useTypes == null && this.entities != null)
                {
                    this.useTypes = new EntityObservableCollection<UseType>(this.entities.UseTypes);
                }
                return this.useTypes;
            }
        }

        public ObservableCollection<UseTypeCategory> UseTypeCategories
        {
            get
            {
                if (this.useTypeCategories == null && this.entities != null)
                {
                    this.useTypeCategories = new EntityObservableCollection<UseTypeCategory>(this.entities.UseTypeCategories);
                }
                return this.useTypeCategories;
            }
        }
        #endregion
    }
}
